package com.tm.fiverole.controller;

import com.tm.fiverole.entity.UserEntity;
import com.tm.fiverole.entity.Vo.UserVo;
import com.tm.fiverole.result.Result;
import com.tm.fiverole.result.ResultEnum;
import com.tm.fiverole.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

/**
 * @author wangSang
 * @create 2022-08-18 14:41
 */
@RequestMapping("user")
@RestController
public class UserController {


    @Autowired
    private UserService userService;

    /**
     * 登录验证
     *
     * @param user
     * @return
     */
    @PostMapping("login")
    public Result LogIn(@RequestBody UserEntity user) {

        return userService.LogInUser(user);
    }

    /**
     * 分页查询
     *
     * @param user
     * @return
     */
    @GetMapping("queryUser")
    @PreAuthorize("hasPermission('query','打钱222')")
    public Result queryUser(@RequestBody UserVo user) {

        return userService.queryUser(user);
    }

    /**
     * 新增用户与角色关联表
     *
     * @param user
     * @return
     */

    @PostMapping("addUser")
    public Result addUser(@RequestBody UserEntity user) {

        return userService.addUser(user);
    }

    /***
     * 修改用户
     * @param user
     * @return
     */
    @PutMapping("updateUser")
    public Result updateUser(@RequestBody UserEntity user) {

        return userService.updateUser(user);
    }

}
